﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows;

namespace WpfApplication1.ViewModels
{
    using OxyPlot;
    using OxyPlot.Series;
    using System.Windows.Input;

    public class MainViewModel
    {
        public IList<IDataPoint> Points { get; private set; }

        public PlotModel altitudePlotModel { get; private set; }
        public PlotModel speedPlotModel { get; private set; }

        private Controllers.MainController mainController;
        public LineSeries altitudeLineSeries { get; private set; }
        public LineSeries speedLineSeries { get; private set; }

        public ICommand testButton { get; private set; }
        public MainViewModel()
        {
            testButton = new Updater(new Action(closeProgram));

            //createa altitude plotmodel
            altitudePlotModel = new PlotModel("altitude");
            altitudeLineSeries = new LineSeries("altitude");
            altitudePlotModel.Series.Add(altitudeLineSeries);

            //createa speed plotmodel
            speedPlotModel = new PlotModel("speed");
            speedLineSeries = new LineSeries("speed");
            speedPlotModel.Series.Add(speedLineSeries);

            mainController = new Controllers.MainController(this);
        }

        public void closeProgram()
        {
            mainController.udpServer.terminateUdpServer(); 
            Application.Current.Shutdown();
        }
        private class Updater : ICommand
        {
            private Action action;

            public Updater(Action action)
            {
                this.action = action;
            }
            public bool CanExecute(object parameter)
            {
                return true;
            }
            public event EventHandler CanExecuteChanged;
            public void Execute(object parameter)
            {
                action();
            }
        }
    }
}
